package com.example.demo.mapper;

import com.example.demo.entity.StudentInfo;
import com.example.demo.vo.StudentInfoClassInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StudentInfoMapper {
    //SQL 语句操作后的返回类型；一个有意义的方法名：参数列表
    @Select("SELECT * FROM twentyonedata.student_info where stu_name like '%${name}%'")
    List<StudentInfo> getAllStudentInfo(String name);

    @Select("SELECT stu.*,cls.classname FROM student_info stu join classinfo cls on stu.clsid=cls.clsid where stu_name like '%${stuName}%'")
    List<StudentInfoClassInfo> getAllStuAndClassByName(String stuName);

    @Delete("delete from student_info where stuid=#{stuid}")
    Integer deleteByID(Integer stuid);

    @Select("SELECT stu.*,cls.classname FROM student_info stu join classinfo cls on stu.clsid=cls.clsid\n" +
            " where stu_name like  '%${stuName}%' and stu.clsid=#{clsid}")
    List<StudentInfoClassInfo>getAllStuAndClassByclsAndName(String stuName,Integer clsid);


    @Insert("insert into student_info(stu_no,stu_name,stu_sex,stu_birthday,stu_education,stu_interest,my_color,create_date,clsid) \n" +
            " values(#{stu_no},#{stu_name},#{stu_sex},#{stu_birthday},#{stu_education},#{stu_interest},#{my_color},sysdate(),#{clsid})")
    Integer insertStudentInfo(StudentInfo studentInfo);

    @Update("update student_info set clsid=#{clsid},stu_no=#{stu_no},stu_name=#{stu_name},stu_sex=#{stu_sex},stu_birthday=#{stu_birthday},stu_education=#{stu_education},stu_interest=#{stu_interest},my_color=#{my_color} \n" +
            " where stuid=#{stuid}")
    Integer updateStudentInfo(StudentInfo studentInfo);
}
